**
** Fig 1A: Adoption of Acquirer-Linked EMR 
** 
** Construct underlying data 
** 



set more off
clear
cap log close 
log using vendor_shares_analysis.log, replace



** Settings
local fpath_himss_main = "/disk/agedisk4/medicare.work/sacarny-DUA51934/shruthi-dua51934/replication_files/himss/"

local fpath_input = "`fpath_himss_main'input"

local fpath_output = "`fpath_himss_main'output"

local fpath_main = "/disk/agedisk4/medicare.work/sacarny-DUA51934/shruthi-dua51934/replication_files/build/output"


local fpath_output_rep = "/homes/nber/shruthi-dua51934/sacarny-DUA51934/shruthi-dua51934/replication_files/output_20230606"


** control which sections of code to run 
local compute_shares = 0
local clean_shares = 1 



** Compute shares 
if `compute_shares' == 1{


	use "`fpath_output'/acq_applications_status_20230306.dta", clear 

	gen v_acq = strpos(vendor, "legacy_vendor")

	collapse (max) target target2 acq_legacy acq_other (sum) v_acq, by(id year) 

	replace v_acq = 1 if v_acq > 0 

	keep if target ==1 | acq_legacy == 1 

	forvalues y = 2003/2014 {
		di "The year is `y'"
		reg v_acq target acq_legacy if year == `y', nocons robust cluster(id)
	
		if `y' > 2003{
			regsave target acq_legacy using "`fpath_output_rep'/acq_emr_adoption", addlabel("year", `y') nose append
		}
		if `y' == 2003{
		regsave target acq_legacy using "`fpath_output_rep'/acq_emr_adoption", addlabel("year", `y') nose replace
		}
}

}
 
 
** Clean up the shares 
if `clean_shares' == 1 {
	
	use "`fpath_output_rep'/acq_emr_adoption", clear
	
	drop r2 N 
	
	gen acq_gr_name = "Target" if var == "target"
	replace acq_gr_name = "Acquirer" if var == "acq_legacy"
	drop var 
	
	gen acq_gr = 1 if acq_gr_name == "Acquirer"
	replace acq_gr = 3 if acq_gr_name == "Target"
	
	order year acq_gr coef acq_gr_name 
	sort year acq_gr 
	
	export delim using "`fpath_output_rep'/acq_emr_adoption_for_adam.csv", replace 
}
















